package com.watson.todolist.database;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

/**
 * The database manager class handles opening and closing the database. It also
 * handles creating a database if it does not exist when called upon.
 * 
 * @author Donnie Ward
 * 
 * @since 1.0
 */
public class DatabaseManager {
	/**
	 * Database instance
	 */
	private SQLiteDatabase db;
	/**
	 * DatabaseHelper instance
	 */
	private DatabaseHelper dbHelper;

	/**
	 * Opens the database with read and write access
	 * 
	 * @param context
	 *            - A reference to the class requesting to open the database
	 * @return db - Database instance
	 * @throws SQLException
	 */
	public SQLiteDatabase open(Context context) throws SQLException {
		dbHelper = new DatabaseHelper(context);
		db = dbHelper.getWritableDatabase();
		return db;
	}

	/**
	 * Closes the database
	 */
	public void close() {
		dbHelper.close();
	}
}
